//
//  AddressListCell.m
//  MobileShoppingMall
//
//  Created by 冯传昌 on 2021/4/27.
//  Copyright © 2021 冯传昌. All rights reserved.
//

#import "AddressListCell.h"

@interface AddressListCell()

@property (nonatomic,strong) UILabel *nameWithPhoneLB;

@property (nonatomic,strong) UILabel *addressLB;


@property (nonatomic,strong) UIButton *editBtn;

@property (nonatomic,strong) UIButton *deleteBtn;



@end

@implementation AddressListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = MainBackColor;
        self.contentView.backgroundColor = MainBackColor;
        [self initUI];
    }
    return self;
}

#pragma mark - setter
- (void)setModel:(AddressModel *)model{
    _model = model;
    
    self.nameWithPhoneLB.text = [NSString stringWithFormat:@"%@   %@",_model.linker,_model.linkphone];
    self.addressLB.text = [NSString stringWithFormat:@"%@ %@ %@ %@",_model.province,_model.city,_model.region,_model.address];
}

#pragma mark - UI
-(void)initUI{
    [self.contentView addSubview:self.nameWithPhoneLB];
    [self.contentView addSubview:self.addressLB];
    [self.contentView addSubview:self.editBtn];
    [self.contentView addSubview:self.deleteBtn];
    
    UIView *lineV = [[UIView alloc] initWithFrame:CGRectMake(15, 74, ScreenWidth-30, 1)];
    lineV.backgroundColor = RGBA(0, 0, 0, 0.1f);
    [self.contentView addSubview:lineV];
}
#pragma mark - lazy
- (UILabel *)nameWithPhoneLB{
    if (!_nameWithPhoneLB) {
        _nameWithPhoneLB = [[UILabel alloc] initWithFrame:CGRectMake(15, 14, ScreenWidth - 15 - 70, 20)];
        _nameWithPhoneLB.textColor = MainBlackTextColor;
        _nameWithPhoneLB.font = FontSet(15);
        _nameWithPhoneLB.textAlignment = NSTextAlignmentLeft;
    }
    return _nameWithPhoneLB;
}

- (UILabel *)addressLB{
    if (!_addressLB) {
        _addressLB = [[UILabel alloc] initWithFrame:CGRectMake(15, 40, ScreenWidth - 15 - 70, 17)];
        _addressLB.textColor = MainGrayTextColor;
        _addressLB.font = FontSet(12);
        _addressLB.textAlignment = NSTextAlignmentLeft;
    }
    return _addressLB;
}


- (UIButton *)editBtn{
    if (!_editBtn) {
        _editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _editBtn.frame = CGRectMake(ScreenWidth-70, 25, 25, 25);
        [_editBtn setImage:LoadImage(@"地址_编辑") forState:normal];
        [_editBtn addTarget:self action:@selector(editAddressClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _editBtn;
}
- (UIButton *)deleteBtn{
    if (!_deleteBtn) {
        _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _deleteBtn.frame = CGRectMake(self.editBtn.right+10, 25, 25, 25);
        [_deleteBtn setImage:LoadImage(@"地址_删除") forState:normal];
        [_deleteBtn addTarget:self action:@selector(deleteAddressClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteBtn;
}


#pragma mark - SEL
//编辑地址
-(void)editAddressClick{
    if (self.editAddressInfoBlock) {
        self.editAddressInfoBlock(self.model);
    }
}
//删除地址
-(void)deleteAddressClick{
    if (self.deleteAddressBlock) {
        self.deleteAddressBlock(self.model);
    }
}

@end
